package com.uniflow.common;

/**
 * 响应码枚举
 * 
 * @author uniflow
 * @since 1.0.0
 */
public enum ResultCode {
    
    // 通用响应码
    SUCCESS(200, "操作成功"),
    ERROR(500, "操作失败"),
    
    // 参数相关
    PARAM_ERROR(400, "参数错误"),
    PARAM_MISSING(400, "缺少必要参数"),
    PARAM_INVALID(400, "参数格式不正确"),
    
    // 认证相关
    UNAUTHORIZED(401, "未授权访问"),
    TOKEN_INVALID(401, "令牌无效"),
    TOKEN_EXPIRED(401, "令牌已过期"),
    LOGIN_FAILED(401, "登录失败"),
    PASSWORD_ERROR(401, "密码错误"),
    USER_INFO_FAILED(401, "获取用户信息失败"),
    PASSWORD_CHANGE_FAILED(500, "密码修改失败"),
    TOKEN_VALIDATION_FAILED(401, "令牌验证失败"),
    REGISTER_FAILED(500, "注册失败"),
    TOKEN_REFRESH_FAILED(401, "令牌刷新失败"),
    LOGOUT_FAILED(500, "登出失败"),
    
    // 权限相关
    FORBIDDEN(403, "权限不足"),
    ACCESS_DENIED(403, "访问被拒绝"),
    
    // 资源相关
    NOT_FOUND(404, "资源不存在"),
    USER_NOT_FOUND(404, "用户不存在"),
    ROLE_NOT_FOUND(404, "角色不存在"),
    ORG_NOT_FOUND(404, "组织不存在"),
    ORGANIZATION_NOT_FOUND(404, "组织不存在"),
    PROCESS_NOT_FOUND(404, "流程不存在"),
    TASK_NOT_FOUND(404, "任务不存在"),
    
    // 查询相关
    QUERY_FAILED(500, "查询失败"),
    
    // 业务相关
    USER_EXISTS(409, "用户已存在"),
    EMAIL_EXISTS(409, "邮箱已存在"),
    USERNAME_EXISTS(409, "用户名已存在"),
    ROLE_EXISTS(409, "角色已存在"),
    ORG_EXISTS(409, "组织已存在"),
    UPDATE_FAILED(500, "更新失败"),
    DELETE_FAILED(500, "删除失败"),
    OPERATION_NOT_ALLOWED(403, "操作不被允许"),
    
    // 状态相关
    USER_DISABLED(423, "用户已被禁用"),
    ACCOUNT_LOCKED(423, "账户已被锁定"),
    
    // 文件相关
    FILE_UPLOAD_ERROR(500, "文件上传失败"),
    FILE_TYPE_ERROR(400, "文件类型不支持"),
    FILE_SIZE_ERROR(400, "文件大小超出限制"),
    
    // 流程相关
    PROCESS_START_ERROR(500, "流程启动失败"),
    TASK_COMPLETE_ERROR(500, "任务完成失败"),
    PROCESS_DEPLOY_ERROR(500, "流程部署失败"),
    
    // 数据同步相关
    SYNC_CONFIG_ERROR(500, "同步配置错误"),
    SYNC_TASK_ERROR(500, "同步任务执行失败"),
    SYNC_SOURCE_ERROR(500, "数据源连接失败"),
    
    // 系统相关
    SYSTEM_ERROR(500, "系统内部错误"),
    DATABASE_ERROR(500, "数据库操作失败"),
    NETWORK_ERROR(500, "网络连接异常"),
    SERVICE_UNAVAILABLE(503, "服务暂不可用");
    
    private final Integer code;
    private final String message;
    
    ResultCode(Integer code, String message) {
        this.code = code;
        this.message = message;
    }
    
    public Integer getCode() {
        return code;
    }
    
    public String getMessage() {
        return message;
    }
    
    /**
     * 根据code获取枚举
     */
    public static ResultCode getByCode(Integer code) {
        for (ResultCode resultCode : values()) {
            if (resultCode.getCode().equals(code)) {
                return resultCode;
            }
        }
        return ERROR;
    }
}